define(['template/cmsMobile/indexTpl','wx.ajax','wx.tpl','wx.upload','wx.validator','vendor/jquery.ztree.all-3.5','vendor/bootstrap-slider.min','vendor/jquery.fancybox'],function(tpl,wx){
    var cmsMobile = {};
    var currentOpenId;
    var zTreeNode,pageUnique;
    var pageInfo = {};
    var isWrite;
    var setting = {
            view: {
                showLine: true,
                // addHoverDom: addHoverDom,
                // removeHoverDom: removeHoverDom,
                selectedMulti: false,
            },
            data: {
                simpleData: {
                    enable:true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPId: ""
                },
                keep:{
                    leaf:true,
                    parent:true
                }
            },
            edit: {
                enable: true,
                editNameSelectAll: true,
                showRemoveBtn: showRemoveBtn,
                drag: {
                    isCopy:true,
                    autoExpandTrigger: true
                }
            },
            callback: {
                onClick:Onclick,
                onDblClick:OnDdClick,
                onMouseDown: OnMouseDown,
                onRightClick: OnRightClick,
                beforeRemove: beforeRemove,
                beforeDrag: beforeDrag,
                beforeDrop:beforeDrop,
                onDrop:onDrop,
                onRemove: OnRemove,
                onRename: OnRename
            }
        };
    function init(id,w){
        isWrite = cmsMobile.isWrite = w;
        var t = new Date().getTime();
        $.when(
            $.ajax('/res/css/cmsMobile.css?_='+t),
            $.ajax('/res/css/bootstrap-slider.min.css'),
            $.ajax('/res/css/jquery.fancybox.css'),
            $.ajax('/res/css/zTreeStyle.css'))
            .done(function(css,sliderCss,fancyboxCss,ztreecss){
                $('<style type="text/css">').append(ztreecss,sliderCss,fancyboxCss,css).appendTo('head');
                $('#window-frame-cmsMobile').html(tpl.container);
                $('#Js-act-search').on("blur input propertychange",searchNode);
                $('#Js-container,#Js-cmsMobile-body').height($('#window-frame-cmsMobile').height()-10);
                $('#Js-cmsMobile-list').height($('#window-frame-cmsMobile').height()-43);
                getInitTreeData();
            });
	}
    function getInitTreeData(){
        wx.sendData('/resource/all','type=3',initTree);
    }
    var zTreeNodeList = [];
    function initTree(data){
        for (var i = data.result.length - 1; i >= 0; i--) {
            data.result[i].isParent = data.result[i].isParent == '1' ?true:false;
        }
        zTreeNode = $.fn.zTree.init($('#Js-cmsMobile-list'), setting,data.result);
    }
   
    function searchNode(){
        var value = $.trim($("#Js-act-search").val());
        if (value === ""){
            getInitTreeData();
            return;
        }
        zTreeNodeList = zTreeNode.getNodesByParamFuzzy("name",value);
        showSearchResult();
    }
    function showSearchResult(){
        if(zTreeNodeList.length > 0 ){
            $.fn.zTree.init($('#Js-cmsMobile-list'), setting,zTreeNodeList);
        }
    }
    function removeHoverDom(treeId, treeNode) {
        $("#diyBtn_space_" +treeNode.id).remove();
    }

    function showRemoveBtn(treeId, treeNode) {
        if(treeNode.children)
            return false;
        else
            return true;
    }

    function Onclick(event, treeId, treeNode,clickFlag,dd){
        if(treeNode.isParent === false && clickFlag === 0){
            window.open(frontWebUrl+'/cms/'+pageUnique+'.html?t='+(new Date().getTime()));
        }
    }

    function OnMouseDown(event, treeId, treeNode) {
        if(treeNode){
            var info = '上次修改人：'+treeNode.modify_by+'&nbsp;&nbsp;&nbsp;&nbsp;     修改时间：'+treeNode.modify_time+'&nbsp;&nbsp;&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp;&nbsp;'+'创建人：'+treeNode.create_by+'&nbsp;&nbsp;&nbsp;&nbsp;     创建时间：'+treeNode.create_time;
            $('#window-bar-cmsMobile').html(info);
        }
    }

    function OnDdClick(event, treeId, treeNode){
        if(treeNode && !treeNode.isParent){
            currentOpenId = treeNode.id;
            wx.sendData('/resource/content','id='+currentOpenId,function(data){
                pageInfo = JSON.parse(data.result.page_info) || {};
                pageUnique = data.result.unique_flag;
                getContent(JSON.parse(data.result.content));
            });
        }
    }

    function popUpItemEdit(data,callback){
        var pop = wx.pop(wx.tpl(tpl.picEdit,data||{min:1,max:30}));
        $(".Js-slider").slider({tooltip:'hide'});
        $(".Js-slider").on("slide", function(slideEvt) {
            $(this).next('span').html(slideEvt.value[0]+' - '+slideEvt.value[1]);
        });
        $('#Js-picEdit-confirm').click(function(){
            $('.cmssetting-picEdit .error').removeClass('error');
            var id = $('#Js-picEdit-id').val()||'';
            var name = $('#Js-picEdit-name').val()||'';
            var desc = $('#Js-picEdit-desc').val()||'';
            var range = $('#Js-picEdit-range').text().split('-');
            pop.close();
            callback({
                id:id,
                name:name,
                desc:desc,
                min:range[0].trim(),
                max:range[1].trim()
            })
        });
    }

    function getContent(data){
        $('#Js-cmsMobile-body').html(wx.tpl(tpl.cmsheader+tpl.cmscontainer+tpl.settingCon,{isWrite:cmsMobile.isWrite|0}));
        $('#Js-cmscont-container').css('overflow-y','auto').height($('.cmsMobile-container').height()-60);
        $('#Js-layout,#Js-image').hover(function(){
            $(this).find('.Js-select-con').fadeIn('fast');
        },function(){
            $(this).find('.Js-select-con').fadeOut('fast');
        });
        $("#Js-cmscont").sortable({
            placeholder: "drag_highlight_y",
            items:".list-group-item",
            handle: ".move",
            filter: ".list-child",
            animation: 150,
            axis: "y",
            opacity: 0.5,
        }).disableSelection();
        
        $('.Js-select-list').click(function(){
            var _this = this;
            $(this).parents('.Js-select-con').hide();
            popUpItemEdit(null,function(data){
                var template = $(wx.tpl(tpl[$(_this).attr('dataType')+'Tpl'],data)).append(tpl.menu);
                var $t = $(template);
                $t.data('setting',data);
                $('#Js-cmscont').append($t);
                sortUpload(); 
            })
        });
       if(data){
            for(var i=0;i<data.length;i++){
                var _tpl  = $(wx.tpl(tplHandle(data[i].type),data[i].setting||{})).append(data[i].type>10?tpl.goodsMenu:tpl.menu);
                var imgarr =  data[i].items||data[i].img;
                for(var j=0;j<imgarr.length;j++){
                    if(data[i].type == 1 || data[i].type ==2 || data[i].type ==3 || data[i].type ==6){
                        _tpl.find('.Js-list-child').append($(wx.tpl(tpl.imgIconSingle,{index:i,path:imgarr[j].initsrc,key:imgarr[j].PAGE_KEY.replace(/"/g,"'"),type:imgarr[j].PAGE_TYPE,name:imgarr[j].name})));
                    }else if(data[i].type == 11){
                        _tpl.find('.Js-list-child').append($(wx.tpl(tpl.goodsListSingleImgIcon,{index:i,path:imgarr[j].initsrc,name:imgarr[j].name,price:imgarr[j].price,gId:imgarr[j].gId})));
                    }else{
                        _tpl.find('.img'+j).append($(wx.tpl(tpl.tplImgIcon,{index:i,path:imgarr[j].initsrc,key:imgarr[j].PAGE_KEY.replace(/"/g,"'"),type:imgarr[j].PAGE_TYPE,name:imgarr[j].name})));
                    }
                }
                // if(imgarr.length){
                //     _tpl.find('.Js-list-child').width(imgarr.length*77);
                // }
                _tpl.data('setting',data[i].setting);
                _tpl.data('index',i);
                $('#Js-cmscont').append(_tpl);
            }
        }
        $('.fancybox').fancybox();
        $('#Js-cmscont').delegate('.Js-click-img','click',function(){
            $('#Js-cmsMobile-goodsInfo').remove();
            $('.Js-click-img,.Js-click-goodsImg').removeClass('imageclick');
            $(this).addClass('imageclick');
            showSettingCon($(this));
        }).delegate('.Js-tpl-delImg','click',function(){
            $(this).parent('.Js-tplImg-con').remove();
        }).delegate('.Js-remove','click',function(){
            var _this = this;
            wx.confirm('是否删除此条目？',{fn:function(){
                $(_this).parents('.Js-list-group').remove();
            }});
        }).delegate('.Js-copy','click',function(){
            var copy = $(this).parents('.Js-list-group').clone();
            $(this).parents('.Js-list-group').after(copy);
        }).delegate('.Js-edit','click',function(){
            var _this = this;
            popUpItemEdit($(this).parents('.Js-list-group').data('setting'),function(data){
                $(_this).parents('.Js-list-group').data('setting',data);
                if(data.name){
                    $(_this).parents('.Js-list-group').find('.cmssetting-title').text(data.name)
                }
            })
        }).delegate('.Js-cmsMobile-addProduction','click',function(){
            var $this = $(this);
            wx.confirm(tpl.goodsListAddProductTpl,{fn:function(){
                addProduction($('#Js-cmsMobile-productId').val(),$this.prev().find('.Js-list-child'));
            }});
        }).delegate('.Js-click-goodsImg','click',function(){
            $('.Js-click-goodsImg,.Js-click-img').removeClass('imageclick');
            $(this).addClass('imageclick');
            $('#Js-setcont').hide();
            var data = {id:$(this).attr('goodsid'),name:$(this).attr('title'),price:$(this).attr('price')};
            $('#Js-cmsMobile-goodsInfo').remove();
            $('#Js-cmsMobile-body').append(wx.tpl(tpl.goodsInfoCon,data));
        });
        sortUpload();
        $('#Js-cms-save').click(function(){
            var data = dataHandle();
            if(data)
                saveContent(data);
        });
        $('#Js-cms-production').click(function(){
            $('#Js-cmscont').append($(tpl.goodsListTpl).append(tpl.goodsMenu));
        });

        $('#Js-cms-setting').click(function(){
            if(!pageInfo.hasOwnProperty('shareInfo')){
               pageInfo = {
                    shareInfo:{
                        'title':'',
                        'descFriend':'',
                        'titleCircleFriends':'',
                        'link':'',
                        'imgUrl':'',
                        'isshare':true,
                        'isgetUserInfo':false
                    }
                }
            }
            wx.pop(wx.tpl(tpl.cmssetting,pageInfo));
            wx.upload($('#Js-uploadIcon'));
            setUniqueFlag();
            $('#Js-cmsSetcon').delegate('.Js-tabs li','click',function(){
                $(this).addClass('active').siblings('li').removeClass('active');
                $('#Js-set-id,#Js-set-share').hide();
                $('#Js-set-'+$(this).data('flag')).show();
            });
            $('#Js-save-shareinfo').off('click').on('click',function(){
                pageInfo.shareInfo = {};
                $('#Js-set-share input').each(function(){
                    if($(this).attr('name') == "isshare" || $(this).attr('name') == "isgetUserInfo"){
                        pageInfo.shareInfo[$(this).attr('name')] = $(this).is(':checked');
                    }else{
                        if($(this).attr('name') != 'file'){
                            pageInfo.shareInfo[$(this).attr('name')] = $(this).val();
                        }
                    }
                });
                 wx.sendData('/resource/save-pageinfo','id='+currentOpenId+'&info='+JSON.stringify(pageInfo),function(data){
                    if(data.status == 0){
                        $.succ('保存成功');
                    }else{
                        $.succ('保存失败');
                    }
                });
            });
            $('#Js-uploadIcon').off('upload').on('upload',function(event,data){
                if(data.status == 0){
                    $('.Js-actIcon').val(data.path);
                    $('#Js-iconImg').attr('src',data.path);
                    $('#Js-iconImg').show();
                }else{
                    $('#Js-iconImg').hide();
                    $('#Js-iconImg').attr('src','');
                    wx.alert('上传失败');
                }
            });
        });
            
    }

    function addProduction(ids,container){
        var pros = ids.split(';');
        var products = [];
        for(var i=0;i<pros.length;i++){
            if(pros[i].length == 0) break;
            products.push('{"goodsID":"'+pros[i]+'","cartMethod":"0","callType":0}');
        }
        wx.sendData('http://sapi.'+(env=='dev'?'beta.':'')+'tootoo.cn/goods/MainServlet?method=getGoodsInfo&req_fmt_type=jsonp&req_str={"channelType":"1","scope":"11101","goodsList":['+products.join(',')+'],"shippingAddress":3,"withGoodsDesc":"0","withExtendsInfo":"0","withSaleCatInfo":"0","withSavInfo":"0","withPicInfo":"1","withSpecialInfo":"0","withPriceInfo":"1","withStockInfo":"0","withShippingInfo":"0","withSkuInfo":"0"}',function(data){
            container.append(wx.tpl(tpl.goodsListImgIcon,{goods:data.Result.Data.goodsInfo}));
            sortUpload();
        });
    }

    function setUniqueFlag(){
        wx.validator();
        wx.validator.addNewRule('allcharNum','只能包括英文字母和数字', function (value) {
            return /^[a-zA-Z0-9]+$/.test(value);
        });
        $('.Js-uniqueId').val(pageUnique);
        $('.Js-pageid').val(currentOpenId);
        $('form[name="uniqueFlag"]').off('validator').on('validator',function(evt,data){
            if(data.status){
                pageUnique = $('.Js-uniqueId').val();
                $.succ('修改成功');
                $('.Js-dialog-close').trigger('click');
            }else{
                $.fail('修改失败');
            }
            
        });
    }
    function sortUpload(){
        $('.addico').droppable({
                //hoverClass:"addicohover glyphicon-trash",
                drop: function(event, ui) {
                    ui.draggable.hide("fast",function(){
                        var list = ui.draggable.parents('.Js-list-group').find('.Js-list-child');
                        ui.draggable.parents('.Js-list-group').find('.addico').removeClass('addicohover glyphicon-trash').addClass('addico glyphicon-plus');
                        ui.draggable.remove();
                        $('#Js-setcont').hide();
                        // list.width(list.find('li').length*77);
                    })
              }
            });
        $(".Js-list-child").sortable({
            placeholder: "drag_highlight_x",
            // axis: "x",
            opacity: 0.5,
            scroll:false,
            start:function(event,ui){
                ui.helper.parents('.Js-list-group').find('.addico').addClass('addicohover glyphicon-trash');
            },
            stop:function(event,ui){
                $(event.target).parents('.Js-list-group').find('.addico').removeClass('addicohover glyphicon-trash').addClass('addico glyphicon-plus');
            }
        }).disableSelection();
        wx.upload($('.Js-addimg'));
        $('.Js-addimg').off('upload').on('upload',function(event,data){
           if(data.status == 0){
                var i = $(this).parents('.Js-list-group').data('index');
                if($(this).attr('istpl')){
                    $(this).parent('.Js-tpl-add').after($(wx.tpl(tpl.tplImgIcon,{path:data.result[0].path,index:i}))); 
                }else{
                    var img = $(wx.tpl(tpl.imgIcon,{path:data.result,index:i})); 
                    var list = $(this).parents('.Js-list-group').find('.Js-list-child');
                    list.append(img);
                    list.width(list.find('li').length*77);
                }
            }else{
                wx.alert('上传失败');
            }
        });
    }
    function tplHandle(type){
        /**
         * tplType 
         * 1 轮播图
         * 2 滚动图
         * 3 广告静态图
         * 4 模板1 一大二小
         * 5 模板2 二小一大
         * 6 商品图*/
       switch (type){
            case "1":
                return tpl.carouselTpl;
                break;
            case "2":
                return tpl.scrollTpl;
                break;
            case "3":
                return tpl.staticTpl;
                break;
            case "4":
                return tpl.tpl1Tpl;
                break;
            case "5":
                return tpl.tpl2Tpl;
                break;
            case "6":
                return tpl.goodsTpl;
                break;
            case "11":
                return tpl.goodsListTpl;
                break;
            default:
                break;

       }

    }
    function dataHandle(){
        var data = [];
        $('.Js-list-group').removeClass('error').each(function(){
            var _data = {
                "setting":$(this).data('setting'),
                "type":$(this).attr('tplType'),
                "items":[]
            };
            if(_data.setting){
                var imgCount = $(this).find('.image').length;
                if(imgCount>_data.setting.max || imgCount<_data.setting.min){
                    $(this).addClass('error');
                    data = [];
                    return false;
                }
            }
            $(this).find('.image').each(function(){
                if(_data.type>10){
                    _data.items.push({'initsrc':$(this).attr('initsrc'),'gId':$(this).attr('goodsid'),'name':$(this).attr('title'),'price':$(this).attr('price')});
                }else{
                    _data.img = _data.img || [];
                    //老版本兼容方案
                    _data.img.push({'initsrc':$(this).attr('initsrc'),'PAGE_TYPE':$(this).attr('type'),'PAGE_KEY':$(this).attr('key').replace(/'/g,'"'),'name':$(this).attr('name')});
                    _data.items.push({'initsrc':$(this).attr('initsrc'),'PAGE_TYPE':$(this).attr('type'),'PAGE_KEY':$(this).attr('key').replace(/'/g,'"'),'name':$(this).attr('name')})
                }
            });
            data.push(_data);
        });
        if(data.length)
            return JSON.stringify(data);
        else 
            return null;
    }
    function valSaveBtnFn(ele,type){
        $('#Js-name-con').show();
        $('.Js-val-save').off('click').on('click',function() {
            var val_obj = {};
            var _flag = false;
            ele.attr('name',$('#Js-image-name').val());
            if(type == 1){
                ele.attr('key',$(this).siblings('input').val());
            }else{
                var _type = $(ele).attr('type');
                $(this).siblings('input').each(function(){
                    if(!_flag){
                        _flag = _type == 5008 && !$(this).val();
                    }   
                
                    val_obj[$(this).attr('v-name')] = $(this).val();
                });
                ele.attr('key',JSON.stringify(val_obj).replace(/"/g,"'"));
            }
            if(_flag){
                return alert("促销ID和商品ID为必填");
            }

            $('#Js-save-result').remove();
            $('#Js-setcont').append($('<div id="Js-save-result" class="save-result">保存成功</div>'));
        });
    }
    function showSettingCon(ele){
        $('#Js-image-name').val('').val(ele.attr('name'));
        var type = ele.attr('type');
        var key = ele.attr('key');
        $.each([5005,5008,5018,5022],function(){
            $('#Js-input-'+this).hide();
        });
        $('#Js-imgset-href').hide();
        for(var i=0;i<$('#Js-select-url option').length;i++){
            if($($('#Js-select-url option')[i]).val() == type){
                $($('#Js-select-url option')[i]).prop('selected',true);
                if(type == 5005 ||type == 5008 || type == 5018|| type == 5022){
                    $('#Js-input-'+type).show();
                    if(key && isNaN(key)){
                        var vals = JSON.parse(key.replace(/'/g,'"'));
                        if(vals){
                            for(x in vals){
                                $('#Js-input-'+type+' .'+x).val(vals[x]);
                            }
                        }
                    }
                    valSaveBtnFn(ele,2);
                }else{
                    if(type != -1 && type != 5021 && type != 5020){
                        $('#Js-imgset-href input').val(key);
                        $('#Js-imgset-href').show();
                        valSaveBtnFn(ele,1);
                    }else{
                        $('#Js-name-con').hide();
                        ele.attr('key','-1');
                    }
                }
            }
        }

        $('#Js-select-url').off('change').on('change',function(){
            var placeholder = $(this).find('option:selected').attr('data-ph');
            type = $(this).find('option:selected').val();
            $.each([5005,5008,5018,5022],function(){
                $('#Js-input-'+this).hide();
                $('#Js-input-'+this+' input').each(function(){
                    $(this).val('');
                });
            });
            $('#Js-imgset-href').hide();
            if(placeholder == -1){
                $('#Js-imgset-href input').val('');
                ele.attr('key','-1');
                ele.attr('type',type);
                $('#Js-name-con').hide();
            }else if(placeholder == -2){
                $('#Js-imgset-href input').val('');
                ele.attr('type',type);
                $('#Js-input-'+type).show();
                valSaveBtnFn(ele,2);
            }else{
                $('#Js-imgset-href input').val('').attr('placeholder',placeholder);
                $('#Js-imgset-href').show();
                ele.attr('key','');
                ele.attr('type',type);
                valSaveBtnFn(ele,1);
            }
        });
        $('#Js-setcont').show();
    }
    function saveContent(data){
        if(!pageUnique){
            wx.alert('请在<span style="color:#337ab7">设置 > 基本信息</span>填写<span style="color:#337ab7">唯一标示</span>并点击<span style="color:#337ab7">修改</span>之后再保存');
            return;
        }
         wx.sendData('/resource/save-content','moduleName=cms&id='+currentOpenId+'&fronturl='+frontWebUrl+'/cms/'+pageUnique+'.html&content='+encodeURI(data),function(data){
            if(data.status == 0){
                $.succ('保存成功');
            }else{
                $.fail('保存失败');
            }
        });

    }
    function OnRightClick(event, treeId, treeNode){
        $('#Js-cmsMobile-contextmenu').remove();
        var menu = false;
        menu = treeNode && treeNode.isParent;
        if(menu === false) return;
        //zTreeNode.selectNode(treeNode);
        if(!treeNode){
            zTreeNode.cancelSelectedNode()
        }
        showRMenu(event);
        $('#Js-cmsMobile-addFile').one('click',function(event){
            createNode(event,0,treeId, treeNode);
            return false;
        });
        $('#Js-cmsMobile-addCate').one('click',function(event) {
            createNode(event,1,treeId, treeNode);
            return false;
        });
    }
    function showRMenu(event){
        if($('#Js-cmsMobile-contextmenu').length){
            $('#Js-cmsMobile-contextmenu').show();
        }else{
            $('body').append(wx.tpl(tpl.contextmenu,event));
        }
        $("body").bind("mousedown", onBodyMouseDown);
    }
    function hideRmenu(){
        if($('#Js-cmsMobile-contextmenu').length){
            $('#Js-cmsMobile-contextmenu').hide();
        }
        $("body").unbind("mousedown", onBodyMouseDown);
    }

    function beforeDrop(treeId, treeNodes, targetNode, moveType, isCopy) {
        if(!targetNode) return false;
        return true;
    }
    function onDrop(event, treeId, treeNodes, targetNode, moveType,isCopy){
        if(!targetNode) return false;
        if(isCopy){
            wx.sendData('resource/copy','sourceId='+treeNodes[0].id+'&pId='+targetNode.id,function(data){
                treeNodes[0].id = data.result.id;
            });
        } else {
            wx.sendData('resource/move','id='+treeNodes[0].id+'&targetId='+targetNode.id);
        }
    }
    function beforeDrag(treeId, treeNodes) {
        if(!isWrite)
            return false;
        
        return !treeNodes[0].isParent
    }

    function OnRename(event, treeId, treeNode, isCancel) {
        wx.sendData('/resource/rename','id='+treeNode.id+'&name='+treeNode.name);
    }

    function OnRemove(event, treeId, treeNode, isCancel) {
        wx.sendData('/resource/remove','id='+treeNode.id);
    }

    function beforeRemove(treeId, treeNode) {
        return confirm("确认删除 " + treeNode.name + " 吗？");
    }

    function createNode(event,isParent,treeId,treeNode){
        var pId = treeNode?treeNode.id:0;
        wx.sendData('/resource/create','type=3&isParent='+isParent+'&pId='+pId,function(data){
            hideRmenu(event);
            add(event,data.result.id,isParent,treeNode);
        });
    }

    function add(event,id,type,treeNode){
        var zTree = $.fn.zTree.getZTreeObj("Js-cmsMobile-list"),
        isParent = type;
        //nodes = zTree.getSelectedNodes(),
        //treeNode = nodes[0];
        if (treeNode) {
            treeNode = zTree.addNodes(treeNode, {id:id, pId:treeNode.id, isParent:isParent, name:"新节点" + id});
        } else {
            treeNode = zTree.addNodes(null, {id:id, pId:0, isParent:isParent, name:"新节点" + id});
        }
        if (treeNode) {
            zTree.editName(treeNode[0]);
        } else {
            alert("子节点被锁定，无法增加子节点");
        }
    }

    function onBodyMouseDown(event){
        if (!(event.target.id == "Js-cmsMobile-contextmenu" || $(event.target).parents("#Js-cmsMobile-contextmenu").length>0)) {
             $('#Js-cmsMobile-contextmenu').hide();
        }
    }

	cmsMobile.init = init;
    return cmsMobile;
});